﻿Imports System.Data
Imports System.Data.OleDb
Public Class Connection
    Dim connect As OleDbConnection
    Dim command As OleDbCommand
    Dim connectString As String = ""

    Public Sub Connecting()
        Try
            connect = New OleDbConnection(connectString)
        Catch ex As Exception
            System.Windows.Forms.MessageBox.Show("Kết Nối Thất Bại !" + ex.Message(), "Thông Báo", Windows.Forms.MessageBoxButtons.OK, Windows.Forms.MessageBoxIcon.Error)
        End Try
    End Sub

    Public Sub Close()
        If connect.State = ConnectionState.Open Then
            connect.Close()
        End If
    End Sub

    Public Function LoadData(ByVal stringCommand As String) As DataTable
        Dim dt As New DataTable()
        Connecting()
        command = New OleDbCommand(stringCommand, connect)
        Dim dtr As New OleDbDataAdapter(command)
        dtr.Fill(dt)
        Close()
        Return dt
    End Function

    Public Function Execute(ByVal stringCommand As String)
        Connecting()
        command = New OleDbCommand(stringCommand, connect)
        Return command.ExecuteNonQuery()
    End Function
End Class
